package com.example.demo.controller;

import com.example.demo.entity.ads;
import com.example.demo.service.AdsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

@Controller
@RequestMapping("/ads")
public class AdsController {
    @Autowired
    private AdsService adsService;

    @GetMapping("/find")
    public @ResponseBody Iterable<ads> getAllAds(){
        return adsService.getAllAds();
    }

    @GetMapping("/find/{id}")
    public @ResponseBody ads getAdsById(@PathVariable int id){
      return adsService.getAdsById(id);
    }

    @RequestMapping("/findByUTime")
    public @ResponseBody ArrayList<ads> getAllAdsByUTime(){
        return adsService.getAdsByUTime(getAllAds());
    }

    @RequestMapping("/findByCTime")
    public @ResponseBody ArrayList<ads> getAllAdsByCTime(){
        return adsService.getAdsByCTime(getAllAds());
    }

    @RequestMapping("/add/{id}")
    public @ResponseBody String addAds(@PathVariable int id){
      return adsService.addAds(id);
    }

    @RequestMapping("/add/{id},{content}")
    public @ResponseBody String addAds(@PathVariable int id,@PathVariable String content){
        return adsService.addAds(id,content);
    }

    @RequestMapping("/delete/{id}")
    public @ResponseBody String deleteAds(@PathVariable int id){ return adsService.deleteAds(id);}

    @RequestMapping("/update/{id},{content}")
    public @ResponseBody String updateAds(@PathVariable int id, @PathVariable String content){ return adsService.updateAds(id,content);}

}
